package com.dongdongshop.common;

import java.io.Serializable;

public class AjaxResult<T> implements Serializable{
    private Integer code;
    private String  message;
    private T  data;

    public static AjaxResult OK(){
        AjaxResult result = new AjaxResult();
        result.setCode(ResultEnum.SUCCESS.getStatus()); //自定义成功返回码
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }

    public static AjaxResult ERROR(){
        AjaxResult result = new AjaxResult();
        result.setCode(AjaxResultCode.ERROR_CODE); //自定义成功返回码
        result.setMessage(AjaxResultCode.ERROR_MESSAGE);
        return result;
    }

    public static AjaxResult R(ResultEnum resultEnum){
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(resultEnum.getStatus());
        ajaxResult.setMessage(resultEnum.getStatusInfo());
        return ajaxResult;
    }


    public AjaxResult() {
    }

    public AjaxResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public AjaxResult<T> setData(T data) {
        this.data = data;
        return this;
    }
}
